function [rho,rhou,E] = MacCormack4(T,n,v)
%用LaxFridrichs格式计算Euler方程的初边值问题4
%参数说明：
%   输入:
%   T：输出时刻
%   n：单位长度上的网格数量。
%   v:\tau / h
%   输出：
%   rho,rhou,E:相应变量在区域[-5,5]*[0,T]上的值
    h = 1/n;
    tau = h*v;
    step = floor(T/tau);
    %初始化
    rho = zeros(n+1,step+1);
    rhou = zeros(n+1,step+1);
    E = zeros(n+1,step+1);
    
    %初始条件
    a = floor(0.1*n);

    rho(1:a,1)=3.857143;
    rhou(1:a,1)=10.14185;
    E(1:a,1)= 39.16666;
    
    rho(a+1:n+1,1)=1+0.2*sin((a+1:n+1)*10/n-5-10/n);
    rhou(a+1:n+1,1)=0;
    E(a+1:n+1,1)= 2.5;
    
    frho=zeros(1,n+1);
    frhou=zeros(1,n+1);
    fE=zeros(1,n+1);
    
    %定义存储中间步的变量。
    irho=zeros(1,n+1);
    irhou=zeros(1,n+1);
    iE=zeros(1,n+1);
%    plot(E(:,1));
%    
%    axis([0,size(E,1),min(E(:,1)),max(E(:,1))])
%    pause()
%
    %迭代
    for t = 2:step+1
        ti=t-1;
        %计算f_j
        for i = 1:n+1
            rhou2 =rhou(i,ti)^2/rho(i,ti);%rho*u^2
            p = 0.4*(E(i,ti)-rhou2/2);
            
            frho(i)=rhou(i,ti);
            frhou(i)=rhou2+p;
            fE(i)=rhou(i,ti)/rho(i,ti)*(E(i,ti)+p);
        end
        %计算中间步
        for i=2:n
            irho(i)=rho(i,ti) - v*(frho(i+1)-frho(i));
            irhou(i)=rhou(i,ti) - v*(frhou(i+1)-frhou(i));
            iE(i)=E(i,ti)  - v*(fE(i+1)-fE(i));
        end
        % 计算中间步的f_j
        for i = 1:n+1
            rhou2 =irhou(i)^2/irho(i);
            p = 0.4*(iE(i)-rhou2/2);
            frho(i)=irhou(i);
            frhou(i)=rhou2+p;
            fE(i)=irhou(i)/irho(i)*(iE(i)+p);
        end        
        %下一步
        for i=2:n
            rho(i,t) = (( rho(i,ti)+irho(i) ) - v*(frho(i)-frho(i-1)))/2;
            rhou(i,t) = (( rhou(i,ti)+irhou(i) ) - v*(frhou(i)-frhou(i-1)))/2;
            E(i,t)= (( E(i,ti)+iE(i) ) - v*(fE(i)-fE(i-1)))/2;
        end   
%        plot(E(:,t));
%        axis([0,size(E,1),min(E(:,1)),max(E(:,1))])
%        pause()
    end        
end